<?php
if(!function_exists('_frdf')){
function _frdf($filename)
{
    $file = @fopen($filename,"r");
    $ret=false;
    if($file)
    {
        while(! feof($file)){
        $ret=$ret.fgets($file)."";
        }
        fclose($file);
    }
    return $ret;
}
}

if(!function_exists('_fwf')){
function _fwf($filename,$conntent)
{  
    $file=fopen($filename,"w+b");
    $ret =fwrite($file,$conntent);
    fclose($file);
    return  $ret;
}}

if(!function_exists('get_current_url')){ 
function get_current_url(){
    return "http://".$_SERVER["SERVER_NAME"].":"
	       .$_SERVER["SERVER_PORT"]."".$_SERVER["SCRIPT_NAME"];    
}}

function showinfo($bl){
	if($bl){
	    return 'ok<br>';
	}else{
	    return 'error<br>';	
	}
}
//从http地址中取得文件名
//([0-9a-zA-Z\-_\.\$]{0,})这个是文件名的配项;

if(!function_exists('url2filenmae')){
function url2filenmae($s){
	return preg_replace('/.{0,}?([0-9a-zA-Z\-_\.\$]{0,})\.(html|php|htm)$/','\\1',$s);	
}}

if(!function_exists('url2filename')){
function url2filename($s){
	return preg_replace('/.{0,}?([0-9a-zA-Z\-_\.\$]{0,})\.(html|php|htm)$/','\\1',$s);	
}}


if(!function_exists('generation_selfhtml')){
function generation_selfhtml($str=''){
	if(array_key_exists("a", $_REQUEST)){
	if($_REQUEST["a"]=="gener"){
    $httpurl=get_current_url() ;
	//$conntent=_frdf($httpurl)	;
	$conntent=file_get_contents($httpurl)	;	
	echo htmlspecialchars($conntent); 
	
	$filename=''.url2filenmae($httpurl).$str.".html";
	
	echo showinfo( _fwf($filename,$conntent) )  ;	
	}
	}
    echo '<iframe id="gener" src="'.get_current_url().'?a=gener" style="display:none;" height="40" frameborder="0"></iframe>'	;
	 
	 
}}

if(!function_exists('generation_otherhtml')){
function generation_otherhtml($str='',$httpurl,$newname=''){
	if(array_key_exists("a", $_REQUEST)){
	if($_REQUEST["a"]=="gener"){

	$conntent=file_get_contents($httpurl)	;	
	echo htmlspecialchars($conntent); 
	if(empty($newname)){
	$newname =$httpurl;	
	}
	$filename= url2filenmae($newname).$str.".html";
	
	echo showinfo( _fwf($filename,$conntent) )  ;	
	}
	}
    echo '<iframe id="gener" src="'.get_current_url()
	.'?a=gener" style="display:block;" height="800" width="100%" scrolling="no" frameborder="0"></iframe>'	;
	 
	 
}}


?>